package com.firebird.oms.domain.sm;

// Generated 2009-11-18 14:27:48 by Hibernate Tools 3.2.5.Beta

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 * TismWorker generated by hbm2java
 */
@Entity
@Table(name = "tism_worker", uniqueConstraints = @UniqueConstraint(columnNames = "login_code"))
public class TismWorker implements java.io.Serializable {

	private static final long serialVersionUID = 5530609586986632071L;
	private Integer loginId;
	private String loginCode;
	private Integer staffId;
	private Integer loginType;
	private String loginPwd;
	private Integer loginLevel;
	private Integer loginNum;
	private Date lastChgPwdTime;
	private Integer state;
//	private Set<TismCompany> companies = new HashSet<TismCompany>(0);
	private Set<TismFunction> functions = new HashSet<TismFunction>(0);
	private Set<TismRole> roles = new HashSet<TismRole>(0);

	public TismWorker() {
	}

	public TismWorker(String loginCode, Integer loginType, String loginPwd,
			Integer loginLevel, Integer loginNum, Integer state) {
		this.loginCode = loginCode;
		this.loginType = loginType;
		this.loginPwd = loginPwd;
		this.loginLevel = loginLevel;
		this.loginNum = loginNum;
		this.state = state;
	}

	public TismWorker(String loginCode, Integer staffId, Integer loginType,
			String loginPwd, Integer loginLevel, Integer loginNum, Date lastChgPwdTime,
			Integer state) {
		this.loginCode = loginCode;
		this.staffId = staffId;
		this.loginType = loginType;
		this.loginPwd = loginPwd;
		this.loginLevel = loginLevel;
		this.loginNum = loginNum;
		this.lastChgPwdTime = lastChgPwdTime;
		this.state = state;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "login_id", unique = true, nullable = false)
	public Integer getLoginId() {
		return this.loginId;
	}

	public void setLoginId(Integer loginId) {
		this.loginId = loginId;
	}

	@Column(name = "login_code", unique = true, nullable = false, length = 48)
	public String getLoginCode() {
		return this.loginCode;
	}

	public void setLoginCode(String loginCode) {
		this.loginCode = loginCode;
	}

	@Column(name = "staff_id")
	public Integer getStaffId() {
		return this.staffId;
	}

	public void setStaffId(Integer staffId) {
		this.staffId = staffId;
	}

	@Column(name = "login_type", nullable = false)
	public Integer getLoginType() {
		return this.loginType;
	}

	public void setLoginType(Integer loginType) {
		this.loginType = loginType;
	}

	@Column(name = "login_pwd", nullable = false, length = 36)
	public String getLoginPwd() {
		return this.loginPwd;
	}

	public void setLoginPwd(String loginPwd) {
		this.loginPwd = loginPwd;
	}

	@Column(name = "login_level", nullable = false)
	public Integer getLoginLevel() {
		return this.loginLevel;
	}

	public void setLoginLevel(Integer loginLevel) {
		this.loginLevel = loginLevel;
	}

	@Column(name = "login_num", nullable = false)
	public Integer getLoginNum() {
		return this.loginNum;
	}

	public void setLoginNum(Integer loginNum) {
		this.loginNum = loginNum;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "last_chg_pwd_time", length = 0)
	public Date getLastChgPwdTime() {
		return this.lastChgPwdTime;
	}

	public void setLastChgPwdTime(Date lastChgPwdTime) {
		this.lastChgPwdTime = lastChgPwdTime;
	}

	@Column(name = "state", nullable = false)
	public Integer getState() {
		return this.state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

//	@ManyToMany(cascade = CascadeType.PERSIST)
//	@LazyCollection(LazyCollectionOption.FALSE)
//	@JoinTable(name = "tism_worker_company", joinColumns = { @JoinColumn(name = "login_id") }, inverseJoinColumns = @JoinColumn(name = "company_id"))
//	public Set<TismCompany> getCompanies() {
//		return companies;
//	}
//
//	public void setCompanies(Set<TismCompany> companies) {
//		this.companies = companies;
//	}

	@ManyToMany(cascade = CascadeType.PERSIST)
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "tism_worker_function", joinColumns = { @JoinColumn(name = "login_id") }, inverseJoinColumns = @JoinColumn(name = "func_id"))
	public Set<TismFunction> getFunctions() {
		return functions;
	}

	public void setFunctions(Set<TismFunction> functions) {
		this.functions = functions;
	}

	@ManyToMany(cascade = CascadeType.PERSIST)
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name = "tism_worker_role", joinColumns = { @JoinColumn(name = "login_id") }, inverseJoinColumns = @JoinColumn(name = "role_id"))
	public Set<TismRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<TismRole> roles) {
		this.roles = roles;
	}

	public boolean equals(final Object other) {
		if (!(other instanceof TismWorker))
			return false;
		TismWorker castOther = (TismWorker) other;
		return new EqualsBuilder().append(loginId, castOther.loginId).append(
				loginCode, castOther.loginCode).append(staffId,
				castOther.staffId).append(loginType, castOther.loginType)
				.append(loginPwd, castOther.loginPwd).append(loginLevel,
						castOther.loginLevel).append(loginNum,
						castOther.loginNum).append(lastChgPwdTime,
						castOther.lastChgPwdTime)
				.append(state, castOther.state).append(functions,
						castOther.functions).append(roles, castOther.roles)
				.isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(loginId).append(loginCode).append(
				staffId).append(loginType).append(loginPwd).append(loginLevel)
				.append(loginNum).append(lastChgPwdTime).append(state).append(functions).append(roles).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this).append("loginId", loginId).append(
				"loginCode", loginCode).append("staffId", staffId).append(
				"loginType", loginType).append("loginPwd", loginPwd).append(
				"loginLevel", loginLevel).append("loginNum", loginNum).append(
				"lastChgPwdTime", lastChgPwdTime).append("state", state)
				.append("functions", functions)
				.append("roles", roles).toString();
	}

}
